<!DOCTYPE html>
<!--
  ~ Copyright (C) 2018 guomw.Inc. All rights reserved.
  ~ 项目名称： mysite
  ~ 文件名称： list.html
  ~ Date：18-10-15 下午3:33
  ~ Author: guomw
  -->

<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:include="/common/head::head('报告模板列表')">
<body class="gray-bg">
<div class="wrapper wrapper-content  animated fadeInRight">
    <!--search-->
    <form role="form" class="search-panel">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content p-m no-borders">
                        <div class="form-inline">
                            <div class="form-group m-r-sm">
                                <label class="control-label">报告名称：</label>
                                <input type="text" class="form-control input-sm mb10" id="name" name="name"
                                       placeholder="模糊搜索"/>

                                <button type="button" class="btn btn-success" onclick="jsHelper.search()">查询</button>
                            </div>

                        </div>

                    </div>
                </div>
            </div>
        </div>
    </form>
    <div class="row">
        <div class="col-sm-12" style="text-align: right;margin-bottom: 6px;">
            <a href="/report/edit/0"><button type="button" class="btn btn-success">新增报告模板</button></a>
        </div>
    </div>
    <!--search-->
    <!--list-->
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>报告模板列表</h5>
                </div>
                <div class="ibox-content">
                    <table class="table table-striped">
                        <thead>
                        <tr>

                            <th>编码</th>
                            <th>名称</th>
                            <th>版本号</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody id="table-content">
                        </tbody>
                    </table>
                    <!--分页控件-->
                    <div th:include="/template/pager::pager"></div>
                </div>
            </div>
        </div>
    </div>
</div>
<template id="template_list">
    <tr>
        <td>{code}</td>
        <td>{name}</td>
        <td>{version}</td>
        <!--<td>{template}</td>-->
        <td>
            {btnItems}
        </td>
    </tr>
</template>
<script type="text/html" id="menus_btn_template">
    <a type="button" class="btn-a" data-toggle="modal" data-target="{target}" onclick="{clickMethod}">{title}</a>
</script>

<footer th:include="/common/footer::js"/>
<script>
    /*
 * Copyright (C) 2018 guomw.Inc. All rights reserved.
 * 项目名称： report-manage
 * 文件名称： user.js
 * Date：18-11-6 下午3:16
 * Author: guomw
 */


    $(function () {
        jsHelper.init();
    });
    var jsHelper = {
        templateList: $("#template_list").html(),
        menusbtnTemplate: $("#menus_btn_template").html(),
        params: {
            name: "",
            pageIndex: 1
        },
        init: function () {
            var self = this;
            hotUtil.loading.show();
            hotUtil.ajaxCall("/report/listView", self.params, function (ret) {
                hotUtil.loading.close();
                if (ret.resultCode === 1) {
                    var data = ret.data;
                    var appendHtml = '';
                    $.each(data.list, function (i, item) {
                        var tempHtml = self.templateList;

                        tempHtml = tempHtml.replace(/{code}/gm, item.code);
                        tempHtml = tempHtml.replace(/{name}/gm, item.name);
                        tempHtml = tempHtml.replace(/{version}/gm, item.version);
                        // tempHtml = tempHtml.replace(/{template}/gm, item.template);
                        var btnTempHtml = '<a href="/report/edit/' + item.id + '">修改</a>'
                        + ' <a href="/detection/list/' + item.id + '">配置目标物</a>';
                        tempHtml = tempHtml.replace(/{btnItems}/, btnTempHtml);

                        appendHtml += tempHtml;
                    });
                    $("#table-content").html(appendHtml);

                    var pageinate = new hotUtil.paging(".pagination", jsHelper.params.pageIndex, 20, data.pageCount, data.totalCount, 7);
                    pageinate.init(function (p) {
                        goTo(p, function (page) {
                            jsHelper.params.pageIndex = page;
                            jsHelper.init();
                        });
                    });
                }
            });
        },

        search: function () {
            this.params.pageIndex = 1;
            this.params.name = $("#name").val();
            this.init();
        }
    }

</script>
</body>
</html>
